package com.upb.webserver.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

@Getter
@ToString
@AllArgsConstructor
@Slf4j
public enum FiscoRemoteChainStatusEnum {
    INITIALIZED(0, "初始化"),
    DEPLOYING(1, "部署中"),
    DEPLOY_FAILED(2, "部署失败"),
    RUNNING(3, "运行"),
    RESTARTING(4, "重启中"),
    UPGRADING(5, "升级中"),
    UPGRADING_FAILED(6, "升级失败");


    private byte id;
    private String description;


    FiscoRemoteChainStatusEnum(int id, String description) {
        this.id = (byte) id;
        this.description = description;
    }

    /**
     * @param id
     * @return
     */
    public static FiscoRemoteChainStatusEnum getById(byte id) {
        for (FiscoRemoteChainStatusEnum value : FiscoRemoteChainStatusEnum.values()) {
            if (value.id == id) {
                return value;
            }
        }
        return null;
    }


    /**
     * @return
     */
    public ChainOrAppStatusEnum convertToChainOrAppStatusEnum() {
        switch (this) {
            case INITIALIZED:
                return ChainOrAppStatusEnum.REMOTE_INITIALIZED;
            case DEPLOYING:
                return ChainOrAppStatusEnum.REMOTE_DEPLOYING;
            case DEPLOY_FAILED:
                return ChainOrAppStatusEnum.DEPLOY_FAIL;
            case RUNNING:
                return ChainOrAppStatusEnum.RUNNING;
            case RESTARTING:
                return ChainOrAppStatusEnum.REMOTE_RESTARTING;
            case UPGRADING:
                return ChainOrAppStatusEnum.REMOTE_UPGRADING;
            case UPGRADING_FAILED:
                return ChainOrAppStatusEnum.UPGRADING_FAILED;
        }
        log.error("fail exec method[caseChainOrAppStatusEnum]. not config status:{} desc:{}", this.getId(), this.getDescription());
        return null;
    }
}
